import { Framewok } from "./quick/Framework";
import { StageData } from "./quick/data/StageData";
import { toApp } from "./quick/defines/Decorators";
import { LogLevel } from "./quick/defines/Enums";
import { Singleton } from "./quick/utils/Singleton";
import Alert from "./scripts/common/component/Alert";
import { CmmAudioComp } from "./scripts/common/component/CmmAudioComp";
import Loading from "./scripts/common/component/Loading";
import Tips from "./scripts/common/component/Tips";
import UILoading from "./scripts/common/component/UILoading";
import { UIReconnect } from "./scripts/common/component/UIReconnect";
import UpdateLoading from "./scripts/common/component/UpdateLoading";
import { Config } from "./scripts/common/config/Config";
import { Lang } from "./scripts/common/language/Lang";

/**@description 游戏所有运行单例的管理 */
export class Application extends Framewok{

    /**@description 获取Stage数据 */
    get stageData() {
        return Singleton.get(StageData, true, Config.BUNDLES,Config.DESIGN_RESOLUTION_SIZE)!;
    }

    /**@description 重连专用提示UI部分 */
    get uiReconnect() {
        return Singleton.get(UIReconnect)!;
    }

    /**@description 小提示 */
    get tips() {
        return Singleton.get(Tips)!;
    }

    get uiLoading() {
        return Singleton.get(UILoading)!;
    }

    get alert() {
        return Singleton.get(Alert)!;
    }

    get loading() {
        return Singleton.get(Loading)!;
    }

    get updateLoading() {
        return Singleton.get(UpdateLoading)!;
    }

    private _lang : Lang = null!;
    private get lang(){
        return this._lang || (this._lang = new Lang);
    }

    get gAudio(){
        if ( this._gAudio ){
            return this._gAudio;
        }
        this._gAudio = this.uiManager.addComponent(CmmAudioComp);
        this._gAudio.isGlobal = true;
        return this._gAudio;
    }

    onLoad(node: cc.Node): void {
        this.language.addDelegate(this.lang);
        super.onLoad(node);
    }

    init() {
        super.init();
        this.stageData.isShowDebugButton = Config.isShowDebugButton;
        this.updateManager.hotUpdateUrl = Config.HOT_UPDATE_URL;
        this.updateManager.isAutoVersion = Config.USE_AUTO_VERSION;
        this.updateManager.isSkipUpdate = Config.isSkipUpdate;
        //语言包初始化
        //cc.log("language init");
        this.language.addDelegate(this.lang);
    }
}

let app = new Application();
app.logger.level = LogLevel.ALL;
(<any>window)["App"] = app;
app.init();
toApp();